package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.AlipayTemplate;
import com.atguigu.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@Controller
public class PayController {

    @Autowired
    OrderService orderService;
    @Autowired
    AlipayTemplate alipayTemplate;
    @GetMapping(value = "/payOrder/{orderSn}",produces = "text/html")
    public String payOrder(@PathVariable("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo=orderService.getPayVo(orderSn);
        String pay = alipayTemplate.pay(payVo);
        return pay;
    }
}
